//
//  MBDMineViewModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/4/5.
//

import Foundation
import UIKit
import Toast_Swift
import Alamofire
import SwiftyJSON


// 定义枚举
enum MBDCellLocation {
    case top
    case center
    case bottom
}

class MBDMineCommonCellModel : MBDCommonCellModel {
    var title : String?
    var icon : UIImage?
    var accessory : Bool?
    var nextVCURLString : String?
    var hideSeparateLine : Bool?

    private var innerLocation : MBDCellLocation?

    var location : MBDCellLocation! {
        get {
            if innerLocation != nil {
                return innerLocation
            }
            return .center
        }
        set(lc) {
            self.innerLocation = lc
        }
    }
    
    
    override func cellHeight() -> CGFloat{
        return 55
    }
}

class MBDMineEmptyCellModel : MBDMineCommonCellModel {
    override func cellHeight() -> CGFloat {
        return 5
    }
}

class MBDMineViewModel : NSObject {
    
    var cellModels : NSArray!
    
    static func realName()->String! {
        var resultRealName = ""
        if(!MBDUserCenter.shared.userInfoFetched) {
            resultRealName = "点击登录"
        } else {
            let current = MBDAccountInfoModel.current() ?? MBDAccountInfoModel()
            
            if let realName = current.realName {
                resultRealName = realName
            }
            
            if resultRealName.isBlank {
                if let userId = current.userId {
                    resultRealName = String(format: "用户%@", userId)
                } else {
                    resultRealName = "点击登录"
                }
            } else {
                //do nothign
                debugPrint(resultRealName)
            }
            
        }
        return resultRealName
    }
    
    static var defaultCellModels : NSArray!{
        let rows = NSMutableArray()
        
        let forgroundEmptyCellModel = MBDForgroundEmptyCellModel()
        
        rows.add(forgroundEmptyCellModel)
        
        let avatarCellModel = MBDMineAvatarCellModel()
        
        avatarCellModel.title = MBDMineViewModel.realName()
        avatarCellModel.nextVCURLString = "personalInfo"
        avatarCellModel.accessory = true
        avatarCellModel.hideSeparateLine = true
        rows.add(avatarCellModel)
        
        let emptyCellModel = MBDMineEmptyCellModel()
        rows.add(emptyCellModel)
        
        let publishCellModel = MBDMineCommonCellModel()
        publishCellModel.title = "我创建的"
        publishCellModel.accessory = true
        publishCellModel.nextVCURLString = "postList"
        publishCellModel.location = .top
        publishCellModel.hideSeparateLine = false
        publishCellModel.icon = UIImage(named: "publish")
        rows.add(publishCellModel)
        
        let integrationCellModel = MBDMineCommonCellModel()
        integrationCellModel.title = "积分"
        integrationCellModel.nextVCURLString = "integrate"
        integrationCellModel.accessory = true
        integrationCellModel.location = .center
        integrationCellModel.hideSeparateLine = false
        integrationCellModel.icon = UIImage(named: "ico_integrate_sm")
        rows.add(integrationCellModel)
        
        let settingCellModel = MBDMineCommonCellModel()
        settingCellModel.title = "设置"
        settingCellModel.nextVCURLString = "setting"
        settingCellModel.location = .bottom
        settingCellModel.accessory = true
        settingCellModel.hideSeparateLine = true
        settingCellModel.icon = UIImage(named: "settings_light")
        rows.add(settingCellModel)
        
        return rows
    }
    
    override init() {
        self.cellModels = MBDMineViewModel.defaultCellModels
    }
    
    
}
